data = [{
	'permissions__title': '客户列表',
	'permissions__menu_id': 1,
	'permissions__menu__icon': 'fa-user-o',
	'permissions__menu__title': '客户管理',
	'permissions__url': '/customer/list/'
}, {
	'permissions__title': '添加客户',
	'permissions__menu_id': None,
	'permissions__menu__icon': None,
	'permissions__menu__title': None,
	'permissions__url': '/customer/add/'
}, {
	'permissions__title': '编辑客户',
	'permissions__menu_id': None,
	'permissions__menu__icon': None,
	'permissions__menu__title': None,
	'permissions__url': '/customer/edit/(\\d+)/'
}, {
	'permissions__title': '删除客户',
	'permissions__menu_id': None,
	'permissions__menu__icon': None,
	'permissions__menu__title': None,
	'permissions__url': '/customer/del/(\\d+)/'
}, {
	'permissions__title': '缴费列表',
	'permissions__menu_id': 2,
	'permissions__menu__icon': 'fa-cny',
	'permissions__menu__title': '财务管理',
	'permissions__url': '/payment/list/'
}, {
	'permissions__title': '订单列表',
	'permissions__menu_id': 2,
	'permissions__menu__icon': 'fa-cny',
	'permissions__menu__title': '财务管理',
	'permissions__url': '/order/list/'
},
	{
		'permissions__title': '添加缴费',
		'permissions__menu_id': None,
		'permissions__menu__icon': None,
		'permissions__menu__title': None,
		'permissions__url': '/payment/add/'
	}, {
		'permissions__title': '编辑缴费',
		'permissions__menu_id': None,
		'permissions__menu__icon': None,
		'permissions__menu__title': None,
		'permissions__url': '/payment/edit/(\\d+)/'
	}, {
		'permissions__title': '删除缴费',
		'permissions__menu_id': None,
		'permissions__menu__icon': None,
		'permissions__menu__title': None,
		'permissions__url': '/payment/del/(\\d+)/'
	}]

"""
ret = {
	2 : {
			'title' :'财务管理',
			'icon' : 'fa-cny',
			'weight' : '10',
			'children'：[
					{'url':'/payment/list/'   'title':'缴费列表' id }
					{'url':'/order/list/'   'title':'订单列表' }
			]
		},
	1 : {
		'title' :'客户管理',
		'icon' : 'fa-user-o'
		'weight' : '1',
		'children'：[
				{'url':'/customer/list/'   'title':'客户列表' }
		]
	}
} 

"""

ret = {}
for i in data:
	menu_id = i.get('permissions__menu_id')

	if not menu_id:
		continue
	ret.setdefault(menu_id, {
		'title': i.get('permissions__menu__title'),
		'icon': i.get('permissions__menu__icon'),
		'children': []
	})

	ret[menu_id]['children'].append({'title': i.get('permissions__title'), 'url': i.get('permissions__url')})

print(ret)
